<template>
	<view>
		<view class="top" style="background-image: url(../../static/login/bj.png);">
			<view class="hello">
				HelLo!
			</view>
			<view class="welcome">
				欢迎登录农贸配送系统
			</view>
		</view>
		<view class="user">
			<view class="user1">
				<view class="type">
					+86
				</view>
				<view class="input">
					<input v-model="phoneNum" maxlength="15" type="text" value="" placeholder="请输入手机号" />
				</view>
			</view>
		</view>
		<view class="pass">
			<view class="passinfo">
				<view class="passLeft">
					<input v-model="number" type="text" value="" placeholder="请输入密码" />
				</view>
				<view class="passRight">
					X
				</view>
			</view>
		</view>
		<view class="get" @click="getYZM">
			{{isNumName}}
		</view>
		
		<view class="buttonSub">
			<view class="subInfo" @click="sub()">
				立即登陆
			</view>
		</view>
		
		<view class="reg">
			还没有账号？去注册
		</view>
		
	</view>
</template>
<style lang="scss" scoped>
.reg{width: 100%;margin-top: 100rpx;
	text-align: center;color: #999999;font-size: 25rpx;//background: green
}
.buttonSub{
	width: 100%;height: 90rpx;
	.subInfo{height: 86rpx;margin-left: 40rpx;margin-right: 40rpx;margin-top: 123rpx;
		background: #288EED;font-size: 32rpx;font-weight: 400;margin-bottom: 100rpx;
color: #FFFFFF;text-align: center;line-height: 86rpx;
		box-shadow: 0rpx 10rpx 10rpx 0rpx rgba(0, 122, 255, 0.2);
		border-radius: 40rpx;
	}
}
	
.get{color: #288EED;margin-top: 30rpx;
	text-align: right;padding-right: 50rpx;font-size: 26rpx;
}
.pass{
	height: 140rpx;overflow: hidden;
	.passinfo{background: #F6F6F6;height: 100rpx;border-radius: 49rpx;display: flex;
		margin-left: 68rpx;margin-right: 66rpx;margin-top: 20rpx;
		.passLeft{
			flex: 1;
			input{font-size: 28rpx;color: #999;
				height: 70rpx;margin-top: 15rpx;padding-left: 30rpx;
			}
		}
		.passRight{
			width: 20px;line-height: 100rpx;color: #288EED;
		}
	}
}
.user{
	height: 140rpx;overflow: hidden;
	.user1{background: #F6F6F6;height: 100rpx;border-radius: 49rpx;display: flex;
		margin-left: 68rpx;margin-right: 66rpx;margin-top: 20rpx;
		.input{width: 100%;
			height: 100rpx;//background: green;
			input{padding-left: 30rpx;color: #999;font-size: 28rpx;
				height: 70rpx;margin-top: 15rpx;
			}
		}
		.type{height: 40rpx;margin-top: 25rpx;line-height: 50rpx;
			padding-left: 33rpx;border-right: #c5c9c9 solid 1rpx;
			width: 124rpx;color: #288EED;font-size: 28rpx;
			//background: green;
		}
	}
}
.top{
	height: 500rpx;overflow: hidden;
	.hello{margin-top: 100rpx;padding-left: 54rpx;
		color: #FFF;font-size: 50rpx;
	}
	.welcome{color: #fff;
		margin-top: 30rpx;padding-left: 54rpx;font-size: 46rpx;
	}
}
</style>
<script>
	export default {
		data() {
			return {
				phoneNum:"",//手机号码
				number:"",//短信验证码内容
				isNum:false,//默认是false  
				isNumName:"获取验证码"
			}
		},
		
		methods: {
			//发送验证码
			getYZM(){
				var _this=this;
				var phoneNum=this.phoneNum;
				if(""==phoneNum){
					_this.$u.toast("手机号码不能为空");
				}else{
					if(_this.isNum){
						_this.$u.toast("请先获取验证码");
					}else{
						_this.isNumName="验证码已发送...";
						_this.isNum=true;
						var dataPar={
							mobile:phoneNum,
							event:"mobilelogin"
						}
						_this.$u.api.send(dataPar).then(res => {
							_this.$u.toast("验证码发送成功...");
							//alert(JSON.stringify(res));
						});
						
					}
				}
			},
			
			sub(){
				var _this=this;
				var phoneNum=this.phoneNum;
				var number=this.number;
				if(""==phoneNum){
					_this.$u.toast("手机号码不能为空");
				}else{
					if(phoneNum.length==11){
						if(""==number){
							_this.$u.toast("验证码不能为空！请检查...");
						}else{
							
							let form = {
								"account":phoneNum,
								"password":number
							}
							this.$u.post('api/user/login', form).then(res => {	
										let userinfo =  res.userinfo;
										uni.setStorageSync('userinfo', userinfo);
										uni.setStorageSync('token', userinfo.token);
										uni.redirectTo({
											url:'../main/main'
										})	  
							})
							
							return false;
							let dataPar={
								"mobile":phoneNum,
								"captcha":number
							}
							this.$u.api.mobilelogin(dataPar).then(res => {
								uni.setStorageSync('userinfo',res.userinfo);
								
								uni.setStorageSync('token',res.userinfo.token);
								uni.redirectTo({
									url:'../main/main'
								})
								//alert("res=="+JSON.stringify(res));
								//alert("res=="+JSON.stringify(res.userinfo.token));
							});
						}
						
					}else{
						_this.$u.toast("手机号码不合法！请检查...");
					}
				}
				let dataPar={}
				// this.$u.api.caiCateList(dataPar).then(res => {
				// 	_this.goodsType=res.data;
				// });
			}
		}
	}
</script>


